package com.crm.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ReadURL {
	public static String getURL(String url) {
		StringBuilder sb=new StringBuilder();
		try {
			URL oracle = new URL(url);
			URLConnection yc = oracle.openConnection();
			BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
			
			String c=null;
			while ((c = in.readLine()) != null) 
			    sb.append(c);
			in.close();
			Pattern p=Pattern.compile("<span.*?span>");
			Matcher m=p.matcher(sb.toString());
			sb=new StringBuilder();
			while(m.find()){
				String g=m.group();
				
				System.out.println(" initial strips "+g );
				g=g.replaceAll("\\<a.*?a>", "");
				System.out.println(" strips a tag "+g );
				//g=g.replaceAll("\\<img.*?>", "");
				sb.append(g);
				System.out.println(" strips "+m.group() );
			}
			System.out.println(" output "+sb);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
      return sb.toString();
	}
	public static void main(String[] args) throws Exception{
		String s=ReadURL.getURL("http://www.xe.com/ucc/convert/?Amount=1&From=USD&To=INR");
		//Pattern p=Pattern.compile("\\<.*?>");
		Pattern p=Pattern.compile("\\<span.*?span>");
		Matcher m=p.matcher(s);
		while(m.find()){
			String g=m.group();
			s+=g;
			System.out.println(" initial strips "+g );
			g=g.replaceAll("\\<a.*?a>", "");
			System.out.println(" strips a tag "+g );
			g=g.replaceAll("\\<img.*?>", "");
			System.out.println(" strips img tag "+g );
			
		}
	}
}
